package eu.tolu.cableSpotter.help;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

import eu.tolu.cableSpotter.CountryList;
import eu.tolu.cableSpotter.SpotView;

public class SitesOverlay extends ItemizedOverlay {

	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	Context mContext;
	private ArrayList<String> cabData;
	private Float distance;

	public SitesOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
	}

	public SitesOverlay(Drawable defaultMarker, Context context,
			ArrayList<String> cableData) {
		super(boundCenterBottom(defaultMarker));
		// super(defaultMarker);
		mContext = context;
		this.cabData = cableData;
	}

	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	@Override
	protected boolean onTap(int index) {
		if(cabData == null){
			OverlayItem item = mOverlays.get(index);
			AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
			dialog.setTitle(item.getTitle());
			dialog.setMessage(item.getSnippet());
			dialog.show();
		}else {
			// mContext.startActivity(new Intent(mContext, CountryList.class));
			
			Intent intent = new Intent(mContext, SpotView.class);
			try {
				
			intent.putExtra("country", cabData.get(0));
			intent.putExtra("location", cabData.get(1));
			intent.putExtra("add1", cabData.get(2));
			intent.putExtra("add2", cabData.get(3));
			intent.putExtra("add3", cabData.get(4));
			intent.putExtra("addInfo", cabData.get(5));
			intent.putExtra("phone", cabData.get(6));
			intent.putExtra("fax", cabData.get(7));
			intent.putExtra("email", cabData.get(8));
			intent.putExtra("web", cabData.get(9));
			intent.putExtra("img", cabData.get(10));
			intent.putExtra("custome", cabData.get(11));
			} catch (Exception e) {
				// TODO: handle exception
			}
			mContext.startActivity(intent);
		}

		return true;
	}

}